package com.itheima.myconvertstream;

import java.io.*;
import java.nio.charset.Charset;

public class ConvertStreamDemo3 {
    public static void main(String[] args) throws IOException {
        /*
            将本地文件中的GBK文件，转成UTF-8
        */

        //JDK11版本
        /*InputStreamReader isr = new InputStreamReader(new FileInputStream("myio\\c.txt"), "GBK");
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("myio\\d.txt"), "UTF-8");
        int len;
        while ((len = isr.read()) != -1) {
            osw.write(len);
        }
        osw.close();
        isr.close();*/

        //替代版本
        FileReader fr = new FileReader("myio\\c.txt", Charset.forName("GBK"));
        FileWriter fw = new FileWriter("myio\\e.txt",Charset.forName("UTF-8"));
        int len;
        while ((len = fr.read()) != -1) {
            fw.write(len);
        }
        fw.close();
        fr.close();
    }
}
